package com.ymatou.iapi.sellerquery.service;

import org.json.JSONException;
import org.json.JSONObject;

import com.ymatou.query.seller.trading.api.parameter.GetSellerOrderCountResponse;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;

/**
 * 获取商家订单数量Call FreeMaker Template自动生成代码
 */
public class GetSellerOrderCountCall extends YmatouBaseCall {
	private static String opurl = "api/SellerQuery/GetSellerOrderCount";

	public GetSellerOrderCountCall() {
		super(EnvSetup.getSystemUrl("sellerquery_iapi"), opurl, "POST", "JSON");
	}

	@Override
	public void addDefHeader() {
		client.addHeader("Accept",
				"text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}

	/**
	 * 获取Code
	 * 
	 * @return
	 */
	public String getCode() {
		String Code = null;
		try {
			Code = new JSONObject(getReturnData()).getString("code");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Code;
	}

	/**
	 * 获取BCode
	 * 
	 * @return
	 */
	public String getBCode() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("bcode");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Msg
	 * 
	 * @return
	 */
	public String getMsg() {
		String BCode = null;
		try {
			BCode = new JSONObject(getReturnData()).getString("msg");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return BCode;
	}

	/**
	 * 获取Data
	 * 
	 * @return
	 */
	public JSONObject getData() {
		JSONObject Data = null;
		try {
			Data = new JSONObject(getReturnData()).getJSONObject("data");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return Data;
	}

	public GetSellerOrderCountResponse getSellerOrderCountResponse() {
		return (GetSellerOrderCountResponse) FormatUtil.GSONToObject(
				DataUtil.Json.parseJsonObj(getData().toString()).toString(),
				GetSellerOrderCountResponse.class);
	}

	public int getReceivedNum() {
		int num = 0;
		try {
			JSONObject temp = getData().getJSONObject("AllRecordCountDic");
			num = temp.getInt("Received");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return num;
	}

	public int getSellerAcceptNum() {
		int num = 0;
		try {
			JSONObject temp = getData().getJSONObject("AllRecordCountDic");
			num = temp.getInt("SellerAccept");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return num;
	}

	public int getOrderPostPayNum() {
		int num = 0;
		try {
			JSONObject temp = getData().getJSONObject("AllRecordCountDic");
			num = temp.getInt("OrderPostPay");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return num;
	}

	public int getAccountPaidNum() {
		int num = 0;
		try {
			JSONObject temp = getData().getJSONObject("AllRecordCountDic");
			num = temp.getInt("AccountPaid");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return num;
	}

	public int getUnknowNum() {
		int num = 0;
		try {
			JSONObject temp = getData().getJSONObject("AllRecordCountDic");
			num = temp.getInt("Unkown");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return num;
	}
}
